﻿/** EasyWeb iframe v3.1.5 date:2019-10-05 License By http://easyweb.vip */;
//审核
Changein.AUDIT = function () {
    return 1;
};
//反审核
Changein.UNAUDIT = function () {
    return 0;
};

// 用common.js必须加上Changein.addCtx("${ctxPath}");
Changein.info = function (info) {
    top.layer.msg(info, {icon: 6});
};
Changein.success = function (info) {
    top.layer.msg(info, {icon: 1});
};
Changein.success = function (info, time) {
    if (Number.isSafeInteger(time)) {
        top.layer.msg(info, {icon: 1, time: time})
    } else {
        top.layer.msg(info, {icon: 1});
    }
};

Changein.error = function (info) {
    top.layer.msg(info, {icon: 2});
};
//指定窗口消失时间
Changein.error = function (info, time) {
    if (Number.isSafeInteger(time)) {
        top.layer.msg(info, {icon: 2, time: time})
    } else {
        top.layer.msg(info, {icon: 2});
    }
};
Changein.errorHtml = function (title, info) {
    top.layer.open({
        type: 1,
        title: title,
        skin: 'layui-layer-admin',
        shadeClose: true,
        shade: false,
        maxmin: true, //开启最大化最小化按钮
        area: ['65%', '65%'],
        content: "<div style='padding:0px 8px 0px 8px;'>" + info + "</div>"
    });
};
Changein.confirm = function (tip, ensure) {
    top.layer.confirm(tip, {
        skin: 'layui-layer-admin'
    }, function (index) {
        ensure();
        if (top && top.layer) {
            top.layer.close(index);
            confirmLock = false;
        }
    });
};

Changein.currentDate = function () {
    // 获取当前日期
    var date = new Date();

    // 获取当前月份
    var nowMonth = date.getMonth() + 1;

    // 获取当前是几号
    var strDate = date.getDate();

    // 添加分隔符“-”
    var seperator = "-";

    // 对月份进行处理，1-9月在前面添加一个“0”
    if (nowMonth >= 1 && nowMonth <= 9) {
        nowMonth = "0" + nowMonth;
    }

    // 对月份进行处理，1-9号在前面添加一个“0”
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }

    // 最后拼接字符串，得到一个格式为(yyyy-MM-dd)的日期
    return date.getFullYear() + seperator + nowMonth + seperator + strDate;
};

//日期格式转换成YYYY-MM-dd
Changein.dateToStr = function (date) {
    if (!Changein.isNull(date)) {
        var time = new Date(date);
        var y = time.getFullYear();
        var M = time.getMonth() + 1;
        M = M < 10 ? ("0" + M) : M;
        var d = time.getDate();
        d = d < 10 ? ("0" + d) : d;
        var str = y + "-" + M + "-" + d;
        return str;
    }
    return date;
}
Changein.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    } else {
        return null;
    }
};
Changein.infoDetail = function (title, info) {
    var display = "";
    if (typeof info === "string") {
        display = info;
    } else {
        if (info instanceof Array) {
            for (var x in info) {
                display = display + info[x] + "<br/>";
            }
        } else {
            display = info;
        }
    }
    top.layer.open({
        title: title,
        type: 1,
        skin: 'layui-layer-rim', //加上边框
        area: ['950px', '600px'], //宽高
        content: '<div style="padding: 20px;">' + display + '</div>'
    });
};
Changein.zTreeCheckedNodes = function (zTreeId) {
    var zTree = $.fn.zTree.getZTreeObj(zTreeId);
    var nodes = zTree.getCheckedNodes();
    var ids = "";
    for (var i = 0, l = nodes.length; i < l; i++) {
        ids += "," + nodes[i].id;
    }
    return ids.substring(1);
};
Changein.closeAllLoading = function () {
    layer.closeAll('loading');
};
Changein.getClientHeight = function () {
    var clientHeight = 0;
    if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    }
    return clientHeight;
};
Changein.getClientHeightPx = function () {
    return Changein.getClientHeight() + 'px';
};
//截取时间长度
Changein.subTime = function (str, len) {
    if (Changein.isNull(str)) {
        return '';
    }
    if (str.length <= len) {
        return str;
    }
    return str.substring(0, len);
}
//判断是否是数字
Changein.isNumeric = function (str) {
    return /^[-+]?(?:[1-9]\d*|0)(?:\.\d+)?$/.test(str);
};
//判断是否为金额
Changein.isMoney = function (str) {
    return /(^[1-9](\d+)?(\.\d{1,2})?$)|(^[0-9]$)|(^\d\.[0-9]{1,2}$)|(^\d\.[0]{1}[0-9]{1}$|(^\d\.[0-9]{1}[0]{1}$)$)/.test(str);
};
//将字符转换为数字
Changein.formateNumber = function (str) {
    var s = str.toString();
    var negativeFlag = false;
    if (/^(\-)/.test(s)) {
        negativeFlag = true;
    }
    s = s.replace(/[^\d.]/g, "");//先把非数字的都替换掉，除了数字和.
    s = s.replace(/^\./g, "");//必须保证第一个为数字而不是.
    s = s.replace(/\.{2,}/g, ".");//保证只有出现一个.而没有多个.
    s = s.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");    //保证.只出现一次，而不能出现两次以上
    if (negativeFlag) {
        return -Number(s);
    }
    return Number(s);
};
//判断是否是正整数
Changein.isPositiveInteger = function (str) {
    return /^\+?([1-9]\d*)$/.test(str);
};
//判断是否是整数
Changein.isInteger = function (str) {
    return /^\+?([0-9]\d*)$/.test(str);
};
//判断是否为正小数
Changein.isPositiveDecimal = function (str) {
    return /^\+?(?:0|[1-9]\d*)\.\d+$/.test(str);
};
//判断是否为正数
Changein.isPositiveNumeric = function (str) {
    return /^[+]?(?:[1-9]\d*|0)(?:\.\d+)?$/.test(str);
};
//将字符转换为金额
Changein.formatePrice = function (str, num) {
    num = num > 0 && num <= 20 ? num : 2;
    str = parseFloat((str + "").replace(/[^\d\.-]/g, "")).toFixed(num) + "";//更改这里n数也可确定要保留的小数位
    var l = str.split(".")[0].split("").reverse(), r = str.split(".")[1], t = "";
    for (var i = 0; i < l.length; i++) {
        t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
    }
    var result = t.split("").reverse().join("") + "." + r.substring(0, num);//保留2位小数  如果要改动 把substring 最后一位数改动就可
    return Number(result);
};
//判断值是否存在
Changein.isNull = function (str) {
    if (!str) {
        return true
    }
    ;
    if (str == "undefined" || str == "null") {
        return true
    }
    ;
    if (str.toString().length == 0) {
        return true
    }
    ;
    return false;
};
/**
 * <p>判断值是否相等</p>
 * <p>null, null -> true</p>
 *<p>undefined, undefined -> true</p>
 * <p>NaN, NaN -> true</p>
 * <p>undefined, null -> false</p>
 * <p>null, "" -> false</p>
 * <p>"", "" -> true</p>
 * @param str1
 * @param str2
 * @returns {boolean}
 */
Changein.equals = function (str1, str2) {
    if ((typeof (str1) == "undefined") && (typeof (str2) == "undefined")) {
        return true;
    }
    if ((!str1 && typeof (str1) != "undefined" && str1 != 0) && (!str2 && typeof (str2) != "undefined" && str2 != 0)) {
        return true;
    }
    if (isNaN(str1) && isNaN(str2)) {
        return true;
    }
    if ((typeof (str1) == "boolean") && (typeof (str2) == "boolean")) {
        if (str1 == str2) {
            return true;
        }
        return false;
    }
    if ((typeof (str1) == "number") && (typeof (str2) == "number")) {
        if (str1 == str2) {
            return true;
        }
        return false;
    }
    if ((typeof (str1) == "number") || (typeof (str2) == "number")) {
        str1 = str1 + "";
        str2 = str2 + "";
    }
    if ((typeof (str1) == "string") && (typeof (str2) == "string")) {
        if (str1.length == str2.length) {
            if (str1 == str2) {
                return true;
            }
            return false;
        }
        return false;
    }
    return false;
};
//数组去重，根据id区分
Changein.distinctArrayById = function (arr1, arr2) {
    let arr = arr1.concat(arr2);
    if (arr.length == 0) {
        return arr;
    }
    let obj = {};
    arr = arr.reduce(function (a, b) {
        obj[b.id] ? '' : obj[b.id] = true && a.push(b);
        return a;
    }, []);
    return arr;
};
//删除该数组下的某个元素
Changein.removeArray = function (arr, str) {
    return arr.filter(item => item != str);
};
/**
 * 删除该数组下的某个元素(根据id)
 */
Changein.removeArrayById = function (arr, obj) {
    return arr.filter(item => item.id != obj.id);
};
//左边的数组删掉包含数组的数据
Changein.removeArrayBatch = function (arr1, arr2) {
    var i, j;
    var arr = [].concat(arr1);
    for (i = 0; i < arr1.length; i++) {
        for (j = 0; j < arr2.length; j++) {
            if (arr1[i].id == arr2[j].id) {
                delete arr[i];
                break;
            }
        }
    }
    return arr;
};
//数学运算-加
Changein.addition = function (a, b) {
    var c, d, e;
    try {
        c = a.toString().split(".")[1].length;
    } catch (f) {
        c = 0;
    }
    try {
        d = b.toString().split(".")[1].length;
    } catch (f) {
        d = 0;
    }
    return e = Math.pow(10, Math.max(c, d)), (Changein.multiplication(a, e) + Changein.multiplication(b, e)) / e;
};
//数学运算-减
Changein.subtraction = function (a, b) {
    var c, d, e;
    try {
        c = a.toString().split(".")[1].length;
    } catch (f) {
        c = 0;
    }
    try {
        d = b.toString().split(".")[1].length;
    } catch (f) {
        d = 0;
    }
    return e = Math.pow(10, Math.max(c, d)), (Changein.multiplication(a, e) - Changein.multiplication(b, e)) / e;
};
//数学运算-乘
Changein.multiplication = function (a, b) {
    var c = 0,
        d = a.toString(),
        e = b.toString();
    try {
        c += d.split(".")[1].length;
    } catch (f) {
    }
    try {
        c += e.split(".")[1].length;
    } catch (f) {
    }
    return Number(d.replace(".", "")) * Number(e.replace(".", "")) / Math.pow(10, c);
};
//数学运算-除
Changein.division = function (a, b) {
    var c, d, e = 0,
        f = 0;
    try {
        e = a.toString().split(".")[1].length;
    } catch (g) {
    }
    try {
        f = b.toString().split(".")[1].length;
    } catch (g) {
    }
    return c = Number(a.toString().replace(".", "")), d = Number(b.toString().replace(".", "")), Changein.multiplication(c / d, Math.pow(10, f - e));
};
//修改对table或treeTable的编辑状态
Changein.editTd = function (state) {
    var $ = layui.jquery;
    var tds = $(".layui-table").find('td[data-edit]');
    for (var i = 0; i < tds.length; i++) {
        $(tds[i]).data('edit', state ? "text" : state);
    }
};
//修改table或treeTable的操作按钮
Changein.toolbarState = function (state) {
    var $ = layui.jquery;
    var editTool = $(".layui-btn").filter('[lay-event="' + (state ? "edit_" : "edit") + '"]');
    if (editTool) {
        editTool.attr("lay-event", state ? "edit" : "edit_");
        if (state) {
            editTool.removeClass("layui-btn-disabled");
            editTool.addClass("layui-btn-primary");
        } else {
            editTool.addClass("layui-btn-disabled");
            editTool.removeClass("layui-btn-primary");
        }
    }
    var deleteTool = $(".layui-btn").filter('[lay-event="' + (state ? "delete_" : "delete") + '"]');
    if (deleteTool) {
        deleteTool.attr("lay-event", state ? "delete" : "delete_");
        if (state) {
            deleteTool.removeClass("layui-btn-disabled");
            deleteTool.addClass("layui-btn-danger");
        } else {
            deleteTool.addClass("layui-btn-disabled");
            deleteTool.removeClass("layui-btn-danger");
        }
    }
};
//修改xmSelect编辑状态
Changein.editXmSelect = function (state) {
    var xmSelect = layui.xmSelect;
    if (xmSelect) {
        var xmList = xmSelect.get();
        if (xmList && xmList.length > 0) {
            for (let i = 0; i < xmList.length; i++) {
                xmList[i].update({disabled: !state});
            }
        }
    }
};
//input固定死是readonly的
Changein.inputReadOnly = function () {
    var $ = layui.jquery;
    var chooseBtn = $(".scm-choose-btn");
    if (chooseBtn) {
        for (let i = 0; i < chooseBtn.length; i++) {
            var input = chooseBtn[i].previousElementSibling;
            if (input.nodeName.toLocaleUpperCase() == 'INPUT') {
                $(input).prop("readonly", true);
            }
        }
    }
    var readonly = $("input.readonly");
    if (readonly) {
        for (let i = 0; i < readonly.length; i++) {
            $(readonly[i]).prop("readonly", true);
        }
    }
    var disabled = $("input.disabled");
    if (disabled) {
        for (let i = 0; i < disabled.length; i++) {
            $(disabled[i]).prop("disabled", true);
        }
    }
};
//只读
Changein.formRead = function (firstAuditState, auditState) {
    var $ = layui.jquery;
    $("form").find('input').attr('readonly', true);
    $("form").find('select').attr('disabled', true);
    $("form").find('checkbox').attr('disabled', true);
    $("form").find('radio').attr('disabled', true);
    $("form").find('textarea').attr('readonly', true);
    $("form").find('.scm-choose-btn').hide();
    $("#btnSave").hide();
    $("#btnDel").show();
    $("#btnExp").show();
    $("#btnAudit").show();
    $("#btnUnAudit").show();
    if (firstAuditState == 1) {
        $("#btnDel").hide();
        $("#btnFirstAudit").hide();
        $("#btnFirstUnAudit").show();
        $("#btnUnAudit").hide();
        if (auditState == 1) {
            $("#btnFirstUnAudit").hide();
            $("#btnAudit").hide();
            $("#btnUnAudit").show();
        }
    } else {
        $("#btnDel").show();
        $("#btnFirstAudit").show();
        $("#btnFirstUnAudit").hide();
        $("#btnAudit").hide();
        $("#btnUnAudit").hide();
        if ($("#btnFirstAudit").length == 0) {
            $("#btnAudit").show();
        }
    }
    $('#btnClose').addClass('layui-hide');
    $('#btnSave').addClass('layui-hide');
    $(".scm-form-option").hide();
    Changein.inputReadOnly();
    $(".form-group-bottom").hide();
    Changein.editTd(false);
    Changein.toolbarState(false);
    layui.form.render();
    setTimeout(function () {
        Changein.editXmSelect(false);
        $(":checkbox").attr('disabled', true);
        $(":radio").attr('disabled', true);
        $(":text").attr('disabled', true);
        $(":checkbox").filter("[data-ignore='true']").attr('disabled', false);
        $(":radio").filter("[data-ignore='true']").attr('disabled', false);
        $(":text").filter("[data-ignore='true']").attr('disabled', false);
        layui.form.render();
    }, 500);
    setTimeout(function () {
        $(":checkbox").attr('disabled', true);
        $(":radio").attr('disabled', true);
        $(":text").attr('disabled', true);
        $(":checkbox").filter("[data-ignore='true']").attr('disabled', false);
        $(":radio").filter("[data-ignore='true']").attr('disabled', false);
        $(":text").filter("[data-ignore='true']").attr('disabled', false);
        layui.form.render();
    }, 1500);
};
//审核
Changein.formAudit = function (firstAuditState, auditState) {
    var $ = layui.jquery;
    $("form").find('input').attr('readonly', true);
    $("form").find('select').attr('disabled', true);
    $("form").find('checkbox').attr('disabled', true);
    $("form").find('radio').attr('disabled', true);
    $("form").find('textarea').attr('readonly', true);
    $("form").find('.scm-choose-btn').hide();
    $("#btnSave").hide();
    $("#btnDel").hide();
    $("#btnExp").show();
    $("#btnAudit").show();
    $("#btnUnAudit").show();
    if (firstAuditState == 1) {
        $("#btnFirstAudit").hide();
        $("#btnFirstUnAudit").show();
        $("#btnUnAudit").hide();
        if (auditState == 1) {
            $("#btnFirstUnAudit").hide();
            $("#btnAudit").hide();
            $("#btnUnAudit").show();
        }
    } else {
        $("#btnFirstAudit").show();
        $("#btnFirstUnAudit").hide();
        $("#btnAudit").hide();
        $("#btnUnAudit").hide();
        if ($("#btnFirstAudit").length == 0) {
            $("#btnAudit").show();
        }
    }
    $(".scm-form-option").hide();
    Changein.inputReadOnly();
    //$("button").filter("[lay-submit]").hide();
    $(".form-group-bottom").hide();
    Changein.editTd(false);
    Changein.toolbarState(false);
    $("form").find('input').unbind();
    layui.form.render();
    setTimeout(function () {
        Changein.editXmSelect(false);
        $(":checkbox").attr('disabled', true);
        $(":radio").attr('disabled', true);
        $(":text").attr('disabled', true);
        $(":checkbox").filter("[data-ignore='true']").attr('disabled', false);
        $(":radio").filter("[data-ignore='true']").attr('disabled', false);
        $(":text").filter("[data-ignore='true']").attr('disabled', false);
        layui.form.render();
    }, 500);
    setTimeout(function () {
        $(":checkbox").attr('disabled', true);
        $(":radio").attr('disabled', true);
        $(":text").attr('disabled', true);
        $(":checkbox").filter("[data-ignore='true']").attr('disabled', false);
        $(":radio").filter("[data-ignore='true']").attr('disabled', false);
        $(":text").filter("[data-ignore='true']").attr('disabled', false);
        layui.form.render();
    }, 1500);
};
//未审核且id存在
Changein.formWrite = function (id) {
    var $ = layui.jquery;
    $("form").find('input').attr('readonly', false);
    $("form").find('select').attr('disabled', false);
    $("form").find('checkbox').attr('disabled', false);
    $("form").find('radio').attr('disabled', false);
    $("form").find('textarea').attr('readonly', false);
    $("form").find('.scm-choose-btn').show();
    $("#btnSave").show();
    if (Changein.isNull(id)) {
        $("#btnDel").hide();
        $("#btnExp").hide();
        $("#btnFirstAudit").hide();
        $("#btnAudit").hide();
    } else {
        $("#btnDel").show();
        $("#btnExp").show();
        $("#btnFirstAudit").show();
        $("#btnAudit").hide();
        if ($("#btnFirstAudit").length == 0) {
            $("#btnAudit").show();
        }
    }
    $("#btnUnAudit").hide();
    $("#btnFirstUnAudit").hide();
    $(".scm-form-option").show();
    Changein.inputReadOnly();
    $("button").filter("[lay-submit]").show();
    Changein.editTd(true);
    Changein.toolbarState(true);
    layui.form.render();
    setTimeout(function () {
        Changein.editXmSelect(true);
        layui.form.render();
    }, 500);
};

/**
 *
 * @param excelName table result config id
 * @param settingCode 导出配置的编号
 * @param table 页面传入的table对象
 * @param param 页面查询参数
 */
Changein.exportData = function (tableResultConfigId, settingCode, table, param) {
    var operation = function () {
        var ajax = new layui.ax(Changein.ctxPath + "/exportSetting/export", function (data) {
            if (data.code == 200) {
                table.exportFile(tableResultConfigId, data.data, 'xls');
                console.log(data)
            } else {
                Changein.error("导出失败!" + data.message + "!", 5000);
            }
        }, function (data) {
            Changein.error("导出失败!" + data.responseJSON.message + "!", 5000);
        });
        var requestParam = {};
        requestParam.settingCode = settingCode;
        requestParam.param = param;
        // ajax.set();
        ajax.set({"requestParam": JSON.stringify(requestParam)});
        ajax.start();
    };
    Changein.confirm("是否导出?", operation);

}
// 模板文件下载
Changein.downLoadTempate = function (templateCode) {
    var operation = function () {
        var ajax = new layui.ax(Changein.ctxPath + "/templateInfo/getTemplateInfoByCode", function (data) {
            if (data.code == 200) {
                downLoadFunc(data.data.fileName, data.data.srcPath);
            } else {
                Changein.error("模板下载失败!" + data.message + "!", 5000);
            }
        }, function (data) {
            Changein.error("模板下载失败!" + data.responseJSON.message + "!", 5000);
        });
        ajax.set({"templateCode": templateCode});
        ajax.start();
    };
    Changein.confirm("是否下载模板?", operation);

}

//根据文件名称和下载路径动态创建下载链接下载
function downLoadFunc(templateFileName, templateFileUrl) {

    var aEle = document.createElement("a");// 创建a标签
    // blob = new Blob([content]);
    aEle.download = templateFileName;// 设置下载文件的文件名
    //aEle.href = URL.createObjectUrl(blob);
    aEle.href = Changein.ctxPath + templateFileUrl;// content为后台返回的下载地址
    aEle.click();// 设置点击事件
}

// 查看界面 禁用所有input框和下来框
Changein.isViewInit = function () {
    var form = document.forms[0];
    for (var i = 0; i < form.length; i++) {
        var element = form.elements[i];
        if (element.tagName == 'INPUT') {
            element.readOnly = true;
        }
        if (element.tagName == 'SELECT') {
            element.disabled = true;
        }
    }
}
//校验大于0的正整数
Changein.validateIntNumber = function (num) {
    if (!(/^\d+(?=\.{0,1}\d+$|$)/.test(num))) {
        return false;
    }
    return true;
}

//自动判断
Changein.formState = function () {
    var $ = layui.jquery;
    var id = $("#id").val();
    if (Changein.isNull(id)) {
        id = $("#input[name='id']").val();
    }
    var firstAudit = $("#firstAudit").val();
    if (Changein.isNull(firstAudit)) {
        firstAudit = $("#input[name='firstAudit']").val();
    }
    var audit = $("#audit").val();
    if (Changein.isNull(audit)) {
        audit = $("#input[name='audit']").val();
    }
    if (Changein.isNull(audit)) {
        audit = 1;
    }
    if (Changein.isNull(firstAudit)) {
        firstAudit = audit;
    }
    var isView = Changein.getUrlParam("isView");
    // isView === 1 ->只读
    if (isView && isView === "1") {
        Changein.formRead(firstAudit, audit);
        return;
    }
    // id不存在 ->编辑
    if (Changein.isNull(id)) {
        Changein.formWrite(id);
        return;
    }
    // id存在且审核=0 ->编辑
    if (firstAudit == 0) {
        Changein.formWrite(id);
        return;
    }
    // id存在且审核=1 ->禁止编辑
    if (firstAudit == 1) {
        Changein.formAudit(firstAudit, audit);
        return;
    }
};
// 以下代码是配置layui扩展模块的目录，每个页面都需要引入
layui.config({
    version: Changein.version,
    base: Changein.ctxPath + '/assets/common/module/'
}).extend({
    treeTable: 'treetable-lay/treeTable',
    dropdown: 'dropdown/dropdown',
    notice: 'notice/notice',
    step: 'step-lay/step',
    dtree: 'dtree/dtree',
    citypicker: 'city-picker/city-picker',
    tableSelect: 'tableSelect/tableSelect',
    Cropper: 'Cropper/Cropper',
    zTree: 'zTree/zTree',
    introJs: 'introJs/introJs',
    fileChoose: 'fileChoose/fileChoose',
    tagsInput: 'tagsInput/tagsInput',
    Drag: 'Drag/Drag',
    CKEDITOR: 'ckeditor/ckeditor',
    Split: 'Split/Split',
    cascader: 'cascader/cascader',
    selectPlus: '../../expand/module/selectPlus/selectPlus',
    ax: '../../expand/module/ax/ax',
    axJson: '../../expand/module/ax/axJson',
    ztree: '../../expand/module/ztree/ztree-object',
    iconPicker: '../../expand/module/iconPicker/iconPicker',
    func: '../../expand/module/func/func',
    xmSelect: 'xmSelect/xm-select'
}).use(['layer', 'admin'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var admin = layui.admin;

    // 移除loading动画
    setTimeout(function () {
        admin.removeLoading();
    }, window == top ? 600 : 100);

    //注册session超时的操作
    $.ajaxSetup({
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        complete: function (XMLHttpRequest, textStatus) {

            //如果超时就处理 ，指定要跳转的页面
            if (XMLHttpRequest.getResponseHeader("System-Session-Timeout") === "true") {
                window.location = Changein.ctxPath + "/global/sessionError";
            }

        }
    });

});
var isResultOK = function (res) {
    return res.code === 0 || res.success;
}


//---------------------图片上传-----------------------------
/**
 * 图片上传(支持多图片)
 * @param elemId  选择按钮id
 * @param preImgId  图片预览控件id
 * @param picInputId 图片上传完后返回的key绑定的input表单id
 * @param objData 模块名称和编号需要到开发管理-字典管理-文件上传模块类型中设置
 */
Changein.initUploadImage = function initUploadImage(elemId, preImgId, picInputId, objData) {
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        var filePath = new Array();

        upload.render({
            elem: elemId
            , accept: 'file' //普通文件 images（图片）、file（所有文件）、video（视频）、audio（音频）
            , exts: 'jpg|jpeg|png' //只允许上传指定后缀的文件，一般结合 accept 参数类设定 jpg|png|gif|bmp|jpeg
            , url: Changein.ctxPath + '/file/uploadFile' //统一上传接口，不用改
            , data: objData  // 模块名称和编号需要到开发管理-字典管理-文件上传模块类型中设置
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $(preImgId).show();
                    $(preImgId).attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                if (res.code == 200) {
                    Changein.success("文件上传成功！" + res.data.src);
                    filePath.push(res.data.src);
                    $(picInputId).val(res.data.src);

                    layui.$('#uploadView').removeClass('layui-hide').find('img').attr('src', res.data.src);
                } else {
                    Changein.error("文件上传失败！" + res.data.message, 5000);
                }
            }
            , error: function () {
                Changein.error("上传文件失败！");
            }
        });
    })
}

//---------------------视频上传-----------------------------

/**
 * 视频文件上传(支持多图片)
 * @param elemId  选择按钮id
 * @param preImgId  图片预览控件id
 * @param picInputId 图片上传完后返回的key绑定的input表单id
 * @param objData 模块名称和编号需要到开发管理-字典管理-文件上传模块类型中设置
 */
Changein.initUploadVideo = function initUploadVideo(elemId, preImgId, picInputId, objData, callBack) {
    $('.file-length-tips').show();
    var idx = 0;
    var fileName, previewImgId;
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        //普通图片上传
        var fileName = '';
        var uploadInst = upload.render({
            elem: elemId
            , url: Changein.ctxPath + '/file/uploadFile'
            , data: objData   //模块名称和编号需要到开发管理-字典管理-文件上传模块类型中设置
            , auto: true
            , accept: 'video' //普通文件
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            , choose: function (obj) {
                var item = this.item;
                //获取需要重新上传的目标
                var src;
                var targetImg = $('.upload-con-box input[type=file]').data('targetImg');
                if (targetImg) {
                    src = $('#' + targetImg).attr('src');
                }
                //将每次选择的文件追加到文件队列
                var files = obj.pushFile();
                //预读本地文件示例，不支持ie8
                //result  视频链接（base64）
                obj.preview(function (index, file, result) {
                    // fileName=file.name.substring(0,8);
                    fileName = (Math.random() * 10000).toFixed();
                    //如果是单张图片模式
                    $(picInputId).val('');
                    //删除列表中对应的文件，一般在某个事件中使用
                    delete files[index];
                    //如果是从新上传
                    if (src) {
                        //设置预览图片
                        $('#' + targetImg).attr('src', result)
                            .attr('alt', fileName);//.find('p').attr('id','upErrorText'+fileName)
                        //新增或第一次上传
                    } else {
                        //如果是单张图片模式
                        $(preImgId).empty();
                        var img = '<div class="layui-upload-list img-pre-view">' +
                            '<video class="layui-upload-img pre-img drop-left drop-right" draggable="true" id="adv_pic_img' + fileName + '" src="' + result + '" alt="' + file.name + '" width="320" height="240" controls="controls">' +
                            '<div class="box-del-pic" >' +
                            '<span id="upErrorText' + fileName + '"></span>' +
                            '<a class="del_pic layui-btn layui-btn-danger layui-btn-xs" data-id="' + picInputId + '" targetImg="adv_pic_img' + fileName + '" >删除</a></div>' +
                            '</div>';
                        $(preImgId).append(img).css('display', '');
                        $('#adv_pic_img' + fileName).on('click', function () {
                            var targetImg = $(this).attr('id');
                            $('.upload-con-box input[type=file]').data('targetImg', targetImg).click();
                        });
                        previewImgId = 'adv_pic_img' + fileName;
                        bindDelPicEvent(preImgId, picInputId);
                        dragImgFun(preImgId, picInputId);
                    }
                });
            }
            , done: function (res, index, upload) {
                layer.closeAll('loading'); //关闭loading
                //如果上传失败
                if (!res || res.code != 200) {
                    $(elemId).text("重新上传").css("color", "#ff0041");
                    return layer.msg('上传失败.' + (res ? res.message : ''));
                }
                layer.msg('上传成功', {icon: 1});
                var filePath = res.data.url;
                $('#upErrorText' + fileName).empty();
                //上传成功
                $(elemId).text("重新上传").css("color", "#fff");
                var targetImg = $('.upload-con-box input[type=file]').data('targetImg');
                setUploadImgId(filePath, picInputId, targetImg);
                //回调
                if (callBack) {
                    callBack(res, objData);
                }
            }
            , error: function (obj) {
                layer.closeAll('loading'); //关闭loading
                //演示失败状态，并实现重传
                var upErrorText = $('#upErrorText' + fileName);
                upErrorText.append('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                upErrorText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });
}

/**
 *@description 绑定删除图片事件
 * @param preImgId 图片组件预览盒子id
 * @param picInputId 图片表单输入隐藏input标签id
 **/
function bindDelPicEvent(preImgId, picInputId) {
    $('.del_pic').click(function () {
        var that = $(this);
        var targetImg = that.attr('targetImg');
        picInputId = that.attr('data-id');
        top.layer.confirm("确定删除该图片?", function () {
            // debugger;
            var idx = -1;
            $('.img-pre-view .pre-img').each(function (index) {
                if ($(this).attr('id') == targetImg) {
                    idx = index;
                    return false;
                }
            });
            var picIds = $(picInputId).val();
            if (picIds) {
                var picArr = picIds.split(",");
                picIds = '';
                for (var i in picArr) {
                    if (idx != i) {
                        picIds = picIds + picArr[i] + ",";
                    }
                }
                $(picInputId).val(picIds.substring(0, picIds.length - 1));
            }
            that.parent().parent().remove();
            if ($('.img-pre-view .pre-img').length == 0) {
                $(preImgId).css('display', 'none');
            }
        }, "提示");

    })
}

function dragImgFun(preImgId, picInputId) {
    // 正在拖动的图片的父级DIV
    var $srcImgDiv = null;
    // 开始拖动
    $(".img-pre-view img").bind("dragstart", function () {
        $srcImgDiv = $(this).parent();
    });
    // 拖动到.drop-left,.drop-right上方时触发的事件
    $(".drop-left,.drop-right").bind("dragover", function (event) {
        // 必须通过event.preventDefault()来设置允许拖放
        event.preventDefault();
    });
    // 结束拖动放开鼠标的事件
    $(".drop-left").bind("drop", function (event) {
        event.preventDefault();
        if ($srcImgDiv[0] != $(this).parent()[0]) {
            $(this).parent().before($srcImgDiv);
        }
        //更新input框中的值
        var imgs = $(preImgId + " img");
        if (imgs && imgs.length > 0) {
            var imgInput = "";
            for (var i = 0; i < imgs.length; i++) {
                var src = imgs.eq(i).attr("filepath");
                if ((i + 1) == imgs.length) {
                    //最后一个
                    imgInput = imgInput + src;
                } else {
                    imgInput = imgInput + src + ",";
                }
            }
            $(picInputId).val(imgInput);
        }
    });
    $(".drop-right").bind("drop", function (event) {
        event.preventDefault();
        if ($srcImgDiv[0] != $(this).parent()[0]) {
            $(this).parent().after($srcImgDiv);
        }
        //更新input框中的值
        var imgs = $(preImgId + " img");
        if (imgs && imgs.length > 0) {
            var imgInput = "";
            for (var i = 0; i < imgs.length; i++) {
                var src = imgs.eq(i).attr("filepath");
                if ((i + 1) == imgs.length) {
                    //最后一个
                    imgInput = imgInput + src;
                } else {
                    imgInput = imgInput + src + ",";
                }
            }
            $(picInputId).val(imgInput);
        }
    });
}

/**
 * 保存上传图片的路径到表单(支持多文件id)
 * @param filePath 文件路径
 * @param picInputId 图片input输入表单id
 * @param targetImg 重新上传的img目标id(是否是重新上传)
 **/
function setUploadImgId(filePath, picInputId, targetImg) {
    var img = $(picInputId).val();
    if (img) {
        //重新上传
        if (targetImg) {
            $('.upload-con-box input[type=file]').data('targetImg', '');
            var idx = -1;
            $('.img-pre-view .pre-img').each(function (index) {
                if ($(this).attr('id') == targetImg) {
                    idx = index;

                }
            });

            var imgArr = img.split(',');
            img = '';
            //替换重新上传的图片的id
            for (var i in imgArr) {
                if (i != idx) {
                    img = (img + ',' + imgArr[i]);
                } else {
                    img = img + ("," + filePath);
                }
            }

            //新增上传
        } else {
            img = img + ("," + filePath);
        }
        //首次上传
    } else {
        img = filePath;
    }
    if (img.startsWith(',')) {
        img = img.substring(1, img.length);
    }
    $(picInputId).val(img);
}

/**
 *@description 设置图片预览
 * @param preImgId 图片组件预览盒子id
 * @param picInputId 图片表单输入隐藏input标签id
 *@param picFiles 图片路径
 **/
Changein.setVideoPreView = function setVideoPreView(preImgId, picInputId, picFiles) {
    if (picFiles) {
        $(picInputId).val(picFiles);
        var imgArr = picFiles.split(",");
        for (var i in imgArr) {
            var imgs =
                '<div class="layui-upload-list img-pre-view">' +
                '<video class="layui-upload-img pre-img drop-left drop-right" draggable="true" id="adv_pic_img' + i + '" src="' + Changein.ctxPath + imgArr[i] + '" width="320" height="240" controls="controls">' +
                '<div class="box-del-pic" ><a class="del_pic layui-btn layui-btn-danger layui-btn-xs" data-id="' + picInputId + '"  targetImg="adv_pic_img' + i + '" idx="' + i + '">删除</a></div>' +
                '</div>';
            $(preImgId).append(imgs).css('display', '');
            $('#adv_pic_img' + i).on('click', function () {
                var targetImgId = $(this).attr('id');
                $('.upload-con-box input[type=file]').data('targetImg', targetImgId).click();
            })
        }
        bindDelPicEvent(preImgId, picInputId);
        dragImgFun(preImgId, picInputId);
    }
}

function bindDelPicEvent1(preImgId, picInputId) {
    $('.del_pic').click(function () {
        var that = $(this);
        var targetImg = that.attr('targetImg');
        picInputId = that.attr('data-id');
        top.layer.confirm("确定删除该视频?", function () {
            // debugger;
            var idx = -1;
            $('.img-pre-view .pre-img').each(function (index) {
                if ($(this).attr('id') == targetImg) {
                    idx = index;
                    return false;
                }
            });
            var picIds = $(picInputId).val();
            if (picIds) {
                var picArr = picIds.split(",");
                picIds = '';
                for (var i in picArr) {
                    if (idx != i) {
                        picIds = picIds + picArr[i] + ",";
                    }
                }
                $(picInputId).val(picIds.substring(0, picIds.length - 1));
            }
            that.parent().remove();
            if ($('.img-pre-view .pre-img').length == 0) {
                $(preImgId).css('display', 'none');
            }
        }, "提示");

    })
}


/**
 * 文件上传(支持多图片)
 * @param elemId  选择按钮id
 * @param preImgId  图片预览控件id
 * @param picInputId 图片上传完后返回的key绑定的input表单id
 * @param multiple 是否支持多图片,不传默认false
 */
Changein.initUpload = function initUpload(elemId, preImgId, picInputId, multiple, objData, callBack) {
    // $(elemId).text("添加图片");
    $('.file-length-tips').hide();
    // loadJsOrCssFile('../static/css/imgUpload.css')
    var multiple = multiple == undefined ? false : multiple;
    var idx = 0;
    var fileName, previewImgId;
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        // $(elemId).unbind("click");
        //普通图片上传
        var fileName = '';
        var uploadInst = upload.render({
            elem: elemId
            , url: Changein.ctxPath + '/file/uploadFile'
            , data: objData   //模块名称和编号需要到开发管理-字典管理-文件上传模块类型中设置
            , auto: true
            , accept: 'video'
            , multiple: multiple
            // , number: 1
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            , choose: function (obj) {
                // debugger
                var item = this.item;
                //获取需要重新上传的目标
                var src;
                var targetImg = $('.upload-con-box input[type=file]').data('targetImg');
                if (targetImg) {
                    src = $('#' + targetImg).attr('src');
                }

                //将每次选择的文件追加到文件队列
                var files = obj.pushFile();
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    //result  图片链接（base64）

                    fileName = (Math.random() * 10000).toFixed();

                    //如果是单张图片模式
                    if (!multiple) {
                        // $(preImgId).empty();
                        $(picInputId).val('');
                    }
                    //删除列表中对应的文件，一般在某个事件中使用
                    delete files[index];
                    //如果是从新上传
                    if (src) {
                        //设置预览图片
                        $('#' + targetImg).attr('src', result)
                            .attr('alt', fileName);//.find('p').attr('id','upErrorText'+fileName)

                        // qiNiuPutb64(result,token,picInputId,targetImg);//开始上传
                        //新增或第一次上传
                    } else {
                        //如果是单张图片模式
                        if (!multiple) {
                            $(preImgId).empty();
                        }
                        var img = '<div class="layui-upload-list img-pre-view">' +
                            '<img class="layui-upload-img pre-img drop-left drop-right" draggable="true"' +
                            ' id="adv_pic_img' + fileName + '" src="' + result + '" alt="' + file.name + '">' +
                            '<div class="box-del-pic" >' +
                            '<span id="upErrorText' + fileName + '"></span>' +
                            '<a class="del_pic layui-btn layui-btn-danger layui-btn-xs" data-id="' + picInputId + '" targetImg="adv_pic_img' + fileName + '" >删除</a></div>' +
                            '</div>';
                        $(preImgId).append(img).css('display', '');
                        $('#adv_pic_img' + fileName).on('click', function () {
                            var targetImg = $(this).attr('id');

                            $('.upload-con-box input[type=file]').data('targetImg', targetImg).click();
                        });
                        previewImgId = 'adv_pic_img' + fileName;
                        bindDelPicEvent(preImgId, picInputId);
                        dragImgFun(preImgId, picInputId);
                        // qiNiuPutb64(result,token,picInputId);//开始上传
                    }
                });
            }
            , done: function (res, index, upload) {
                layer.closeAll('loading'); //关闭loading
                //如果上传失败
                if (!res || res.code != '0' || !res.filePath) {
                    $(elemId).css("color", "#ff0041");
                    return layer.msg('上传失败' + (res ? res.message : ''));
                }
                layer.msg('上传成功');
                var filePath = res.filePath;
                $("#adv_pic_img" + fileName).attr("filePath", filePath);
                $('#upErrorText' + fileName).empty();
                //上传成功
                $(elemId).css("color", "#fff");
                var targetImg = $('.upload-con-box input[type=file]').data('targetImg');
                setUploadImgId(filePath, picInputId, targetImg);
                if (res.fileThumb && previewImgId) {
                    $("#" + previewImgId).attr("src", QiniuUrl + res.fileThumb);

                    previewImgId = null;
                }
                //回调
                if (callBack) {
                    callBack(res);
                }
            }
            , error: function (obj) {
                layer.closeAll('loading'); //关闭loading
                //演示失败状态，并实现重传
                var upErrorText = $('#upErrorText' + fileName);
                upErrorText.append('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                upErrorText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });

}


Changein.initUploadVideoBatch = function initUploadVideoBatch(elemId, preImgId, picInputId, objData, multiple, callBack) {
    $('.file-length-tips').show();
    var idx = 0;
    var fileName, previewImgId;
    var multiple = multiple == undefined ? false : multiple;
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        //普通图片上传
        var fileName = '';
        var uploadInst = upload.render({
            elem: elemId
            , url: Changein.ctxPath + '/file/uploadFile'
            , data: objData   //模块名称和编号需要到开发管理-字典管理-文件上传模块类型中设置
            , auto: true
            , multiple: true
            , accept: 'video' //普通文件
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            , choose: function (obj) {
                // debugger
                var item = this.item;
                //获取需要重新上传的目标
                var src;
                var targetImg = $('.upload-con-box input[type=file]').data('targetImg');
                if (targetImg) {
                    src = $('#' + targetImg).attr('src');
                }
                //将每次选择的文件追加到文件队列
                var files = obj.pushFile();
                //预读本地文件示例，不支持ie8
                //result  视频链接（base64）
                obj.preview(function (index, file, result) {
                    // fileName=file.name.substring(0,8);

                    fileName = (Math.random() * 10000).toFixed();
                    //如果是单张图片模式
                    if (!multiple) {
                        $(picInputId).val('');
                    }
                    //删除列表中对应的文件，一般在某个事件中使用
                    delete files[index];
                    //如果是从新上传
                    if (src) {
                        //设置预览图片
                        $('#' + targetImg).attr('src', result)
                            .attr('alt', fileName);//.find('p').attr('id','upErrorText'+fileName)
                        //新增或第一次上传
                    } else {
                        //如果是单张图片模式
                        // $(preImgId).empty();
                        //如果是单张图片模式
                        if (!multiple) {
                            $(preImgId).empty();
                        }
                        // let targetImg1="adv_pic_img"+fileName;
                        // console.log("targetImg1="+targetImg1);
                        var img = '<div targetImg="adv_pic_img'+fileName+'" picInputId="'+picInputId+'"><div class="layui-upload-list img-pre-view" >' +
                            '<video class="layui-upload-img pre-img drop-left drop-right" draggable="true" id="adv_pic_img' + fileName + '" src="' + result + '" alt="' + file.name + '" width="165" height="180" controls="controls"' +
                            '<div class="box-del-pic" >' +
                            '<span id="upErrorText' + fileName + '"></span>' +
                            '</div>'+
                            '<div style="padding-left: 208px;position:absolute; float: left; margin-top:-133px;"><div class="layui-input-inline"><span style="color: red"></span><input id="lessonName"  data-name="lessonName" onblur=\'editLessonName(this)\' placeholder="课时名称"  type="text"  class="layui-input" lay-verify="required" /></div></div>'+
                            "<button type='button' class=\"layui-btn layui-btn-radius layui-btn-danger layui-btn-xs\" onclick='delBtn(this,\""+picInputId+"\")' targetImg=\"adv_pic_img"+fileName+"\" data-id=\"" + picInputId +"_"+fileName+"\">删除</button>"+
                            '</div>';
                        // debugger
                        // console.log("img==="+img);
                        $(preImgId).append(img).css('display', 'block');
                        /*$('#adv_pic_img' + fileName).on('click', function () {
                            var targetImg = $(this).attr('id');
                            $('.upload-con-box input[type=file]').data('targetImg', targetImg).click();
                        });*/
                        previewImgId = 'adv_pic_img' + fileName;
                        // bindDelPicEvent1(preImgId, picInputId);
                        // dragImgFun1(preImgId, picInputId);
                    }
                });
            }
            , done: function (res, index, upload) {
                layer.closeAll('loading'); //关闭loading
                //如果上传失败
                if (!res || res.code != 200) {
                    $(elemId).css("color", "#ff0041");
                    // $(elemId).text("重新上传").css("color", "#ff0041");
                    return layer.msg('上传失败.' + (res ? res.message : ''));
                }
                layer.msg('上传成功', {icon: 1});
                var filePath = res.data.url;
                $("#adv_pic_img" + fileName).attr("filePath", filePath);
                $('#upErrorText' + fileName).empty();
                //上传成功
                $(elemId).css("color", "#fff");
                var targetImg = $('.upload-con-box input[type=file]').data('targetImg');
                setUploadImgMap(filePath, picInputId, -1);
                //
                /* if (res.fileThumb && previewImgId) {
                      $("#" + previewImgId).attr("src",filePath);
                      previewImgId = null;
                  }*/
                //回调
                if (callBack) {
                    callBack(res, objData);
                }
            }
            , error: function (obj) {
                layer.closeAll('loading'); //关闭loading
                //演示失败状态，并实现重传
                var upErrorText = $('#upErrorText' + fileName);
                upErrorText.append('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                upErrorText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });


}

function dragImgFun1(preImgId, picInputId) {
    // 正在拖动的图片的父级DIV
    var $srcImgDiv = null;
    // 开始拖动
    $(".img-pre-view img").bind("dragstart", function () {
        $srcImgDiv = $(this).parent();
    });
    // 拖动到.drop-left,.drop-right上方时触发的事件
    $(".drop-left,.drop-right").bind("dragover", function (event) {
        // 必须通过event.preventDefault()来设置允许拖放
        event.preventDefault();
    });
    // 结束拖动放开鼠标的事件
    $(".drop-left").bind("drop", function (event) {
        event.preventDefault();
        if ($srcImgDiv[0] != $(this).parent()[0]) {
            $(this).parent().before($srcImgDiv);
        }
        //更新input框中的值
        var imgs = $(preImgId + " img");
        if (imgs && imgs.length > 0) {
            var imgInput = "";
            for (var i = 0; i < imgs.length; i++) {
                var src = imgs.eq(i).attr("filepath");
                if ((i + 1) == imgs.length) {
                    //最后一个
                    imgInput = imgInput + src;
                } else {
                    imgInput = imgInput + src + ",";
                }
            }
            $(picInputId).val(imgInput);
        }
    });
    $(".drop-right").bind("drop", function (event) {
        event.preventDefault();
        if ($srcImgDiv[0] != $(this).parent()[0]) {
            $(this).parent().after($srcImgDiv);
        }
        //更新input框中的值
        var imgs = $(preImgId + " img");
        if (imgs && imgs.length > 0) {
            var imgInput = "";
            for (var i = 0; i < imgs.length; i++) {
                var src = imgs.eq(i).attr("filepath");
                if ((i + 1) == imgs.length) {
                    //最后一个
                    imgInput = imgInput + src;
                } else {
                    imgInput = imgInput + src + ",";
                }
            }
            $(picInputId).val(imgInput);
        }
    });
}

//删除当前上传视频
function delBtn(obj,picInputId) {
    var imgMapStr = $(picInputId).val();
    map= jsonToStrMap(imgMapStr); //路径+内容
    let thisObj = $(obj);
    //找到blockquote class的adv_preViewImg_video  ID
    // console.log("map=" + map);
    var targetImg = thisObj.attr('targetImg');
    let filePath = $("#" + targetImg).attr("filePath");
    // console.log("filePath="+filePath);
    if(map.has(filePath)){
        map.delete(filePath);
    } // true
    //上上级
    var twoParent = thisObj.parent().parent();
    var id = twoParent.attr('id'); //adv_preViewImg_video
    let length = twoParent.children().length;
    //  console.log("length=" + length);
    var dataVal = thisObj.attr('data-id');
    //  console.log("dataVal=" + dataVal);
    if (length <= 1) {
        //隐藏
        twoParent.css('display', 'none');
    }
    thisObj.parent().remove();
    //重新放入
   $(picInputId).val(strMapToJson(map));
}
//上传成功之后放入的路径  key 文件路径  value 课时标题
function setUploadImgMap(filePath, picInputId, contentStr) {
    let map = new Map();
    var imgMapStr = $(picInputId).val();
    if (imgMapStr) {
        //之前还上传过的
        map= jsonToStrMap(imgMapStr);
    }
    //路径+内容
    map.set(filePath,contentStr); //放入map中
    imgMapStr = strMapToJson(map);
    // console.log(imgMapStr);
    $(picInputId).val(imgMapStr);
}

/**
 * Map转为对象
 * @param strMap
 * @returns {any}
 */
function strMapToObj(strMap) {
    let obj = Object.create(null);
    for (let [k,v] of strMap) {
        obj[k] = v;
    }
    return obj;
}

/**
 * 对象转为Map
 * @param obj
 * @returns {Map}
 */
function objToStrMap(obj) {
    let strMap = new Map();
    for (let k of Object.keys(obj)) {
        strMap.set(k, obj[k]);
    }
    return strMap;
}

/**
 * Map转为JSON
 * @param strMap
 * @returns {string}
 */
//）
function strMapToJson(strMap) {
    return JSON.stringify(strMapToObj(strMap));
}

/**
 * JSON转为Map
 * @param jsonStr
 * @returns {Map}
 */
function jsonToStrMap(jsonStr) {
    return objToStrMap(JSON.parse(jsonStr));
}

//编辑课时内容
function editLessonName(obj) {
    let thisObj = $(obj);
    var contentStr = thisObj.val(); //内容
    if (!contentStr) {
        contentStr = -1;
    }
    var level3Parent = thisObj.parent().parent().parent();
    var targetImg = level3Parent.attr("targetImg");
    //获取文件路径
    let filePath = $("#" + targetImg).attr("filePath");
    // console.log("filePath=="+filePath);
    //获取pid
    var picInputId = level3Parent.attr("picInputId");
    // console.log("picInputId=="+picInputId);
    setUploadImgMap(filePath, picInputId, contentStr);
}

//回显视频数据
function renderingVideo(filePath,courseContent,picInputId,preImgId) {
    let fileName = (Math.random() * 10000).toFixed();
    var img = '<div targetImg="adv_pic_img'+fileName+'" picInputId="'+picInputId+'"><div class="layui-upload-list img-pre-view" >' + '<video class="layui-upload-img pre-img drop-left drop-right" draggable="true" id="adv_pic_img' + fileName + '" src="' + filePath + '"  width="165" height="180" controls="controls"' +
        '<div class="box-del-pic" >' +
        '<span id="upErrorText' + fileName + '"></span>' +
        '</div>'+
        '<div class="layui-form-item" style=" padding-left: 208px;position:absolute; float: left; margin-top:-133px;"><div class="layui-input-inline"><span style="color: red"></span><input id="lessonName"  data-name="lessonName' + fileName + '" onblur=\'editLessonName(this)\' placeholder="课时名称"  type="text"  class="layui-input" lay-verify="required" /></div></div>'+
        "<button type='button' class=\"layui-btn layui-btn-radius layui-btn-danger layui-btn-xs\" onclick='delBtn(this,\""+picInputId+"\")' targetImg=\"adv_pic_img"+fileName+"\" data-id=\"" + picInputId +"_"+fileName+"\">删除</button>"+
        '</div>';
    // debugger
    // console.log("img==="+img);
    $(preImgId).append(img).css('display', 'block');

    $("input[data-name='lessonName"+fileName+"']").val(courseContent);
    // let filePath="";
    $("#adv_pic_img" + fileName).attr("filePath", filePath);
    $('#upErrorText' + fileName).empty();
}